#! /bin/bash
# wget --no-check-certificate --no-cookies --header "Cookie: oracallicense=accept-securebackup-cookie" www.oracal.com/java/technologies/javase/javase-jdk8-downloads.html/jdk-8u271-linux-x64.tar.gz
ifjava=`whereis java`
java=$(echo ${ifjava} | grep "jdk")
if [[ "$java" != "" ]]
then
    echo "java was installed"
else
    echo "--------------begin install jdk--------------"
    tar -zxvf jdk*.tar.gz
    jdkpath="/usr/local"
    installpath=$(cd `dirname $0`; pwd)
    cd jdk* && jdkname=`pwd | awk -F '/' '{print $NF}'`
    echo "JDK name: ${jdkname}"
    cd ${installpath}
    mv ${jdkname} ${jdkpath}
    echo "JDK installPath: ${jdkpath}/${jdkname}"
    echo "export JAVA_HOME=${jdkpath}/${jdkname}" >> /etc/profile
    echo "export CLASSPATH=$JAVA_HOME/lib/" >> /etc/profile
    echo "export PATH=$PATH:$JAVA_HOME/bin" >> /etc/profile
    source /etc/profile
	echo "--------------install success!------------"
	echo "if java environment invalid please execute command: source /etc/profile"
fi
